import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_tutorial/app/modules/state/getbuilder/counter_controller.dart';

class ObxValuePage extends GetView {

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        title: Text('ObxValue'),
        centerTitle: true,
      ),

      body: SafeArea(
        child: ListView(
          children: [
            Text(
              '- 局部刷新\n- 需要传递一个 Rx 实例',
              style: Theme.of(context).textTheme.headline5
            ),
            Divider(),

            ObxValue<RxBool>(
              (data) {
                print('data: '+data.value.toString());
                return Switch(
                  value: data.value,
                  onChanged: (val) {
                    print('val: '+val.toString());
                    data.value = val;
                  },
                );
              }, 
              false.obs
            )
          ]
        )
      )
    );
  }
}